<template>
  <div>
    <!--操作菜单-->
    <el-form :inline="true" :model="listQuery" class="demo-form-inline">
      <el-form-item label="通知名称">
        <el-input v-model="listQuery.theme" placeholder="通知名称"></el-input>
      </el-form-item>
      <el-form-item label="发送日期">
        <div class="block">
          <el-date-picker
            v-model="listQuery.createTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="发送日期">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getNoticeList">查询</el-button>
      </el-form-item>
    </el-form>
    <!--操作菜单-->
    <el-table
      :data="noticeList"
      border
      v-loading="loading"
      style="width: 100%">
      <el-table-column
        prop="createTime"
        label="创建时间"
      >
      </el-table-column>
      <el-table-column
        prop="theme"
        label="主题">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <!--          <el-button type="primary" icon="el-icon-edit" circle @click="handleEditClick(scope.row)"
                               title="修改"></el-button>-->
          <el-button type="primary" icon="el-icon-edit" circle @click="handleEditClick(scope.row)"
                     title="修改"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="handleDeleteClick(scope.row)"
                     title="删除"></el-button>
          <el-button type="warning" icon="el-icon-document" circle @click="handleDetailClick(scope.row)"
                     title="查看信息"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--查看详情对话框-->
    <el-dialog
      title="未读人员名单"
      :visible.sync="dialogDetailVisible"
      width="80%"
      :before-close="handleDetailClose">
      <notReadDetail :noticeId="noticeId" ref="NoticeNotRead"></notReadDetail>
    </el-dialog>
    <!--修改稿通知对话框-->
    <el-dialog
      title="修改通知"
      :visible.sync="dialogEditVisible"
      width="80%"
      :before-close="handleDetailClose">
      <editNotice :noticeId="noticeId" ref="NoticeEditCall"></editNotice>
    </el-dialog>
    <!--分页-->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="listQuery.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import {deleteNotice, getNoticeList} from "../../api/notice";
  import notReadDetail from "./notReadDetail";
  import editNotice from "./editNotice";

  export default {
    name: "",
    components: {
      notReadDetail,
      editNotice
    },
    data() {
      return {
        loading: true,
        dialogEditVisible:false,
        dialogDetailVisible: false,
        noticeList: [],
        noticeId: '',
        total: '',
        listQuery: {
          page: 1,
          size: 5,
          theme: '',
          createTime: null
        }
      }
    },
    methods: {
      //修改通知
      handleEditClick(param){
        this.noticeId=param.id
        this.dialogEditVisible=true
        this.$nextTick(() => {
          this.$refs['NoticeEditCall'].handleGetDetail()
        })
      },
      getNoticeList() {
        this.loading = true
        getNoticeList(this.listQuery).then(res => {
          console.log("通知列表:")
          console.log(res)
          this.noticeList = res.data.pageList;
          this.total = res.data.total
          this.loading = false
        }).catch(err => {
          this.loading = false
        })

      },
      //分页相关
      handleSizeChange(val) {
        this.listQuery.size = val
        this.getNoticeList()
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        this.getNoticeList()
        console.log(`当前页: ${val}`);
      },
      handleDetailClose() {
        this.dialogDetailVisible = false
        this.dialogEditVisible=false
      },
      //获取未签到名单
      handleDetailClick(param) {
        this.noticeId = param.id
        this.dialogDetailVisible = true
        this.$nextTick(() => {
          this.$refs['NoticeNotRead'].getNoticeNotRead()
        })
      },
      //删除通知
      handleDeleteClick(param) {
        this.loading = true
        deleteNotice({id: param.id}).then(res => {
          if (res.code == 20000) {
            this.$message.success("删除成功")
            this.getNoticeList()
          }
          this.loading = false
        }).catch(err => {
          this.loading = false
        })
      }
    },
    created() {
      this.getNoticeList()
    }
  }
</script>

<style scoped>
  .demo-form-inline {
    margin-top: 20px;
    margin-left: 10px;
  }
</style>
